<?php
/**
 * Created by PhpStorm.
 * User: geyouwen
 * Date: 16/7/4
 * Time: 下午3:35
 */

namespace Backend\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $site = F('site_cache');
        if($site)
        {
            D('settings')->updateSiteCache();
            $site = F('site_cache');
        }
        $this->assign('site_conf', $site);
    }
    public function index()
    {
        if(!session('login_admin'))
        {
            $this->redirect('backend/passport/login');
        }
        $menus = D('menu')->getmenu(0);
        $this->assign('top_menus', $menus);
        $this->assign('admin', session('login_admin'));
        $this->display();
    }

    public function left()
    {
        $menuid = I('menuid', 0, 'intval');
        if ($menuid) {
            $left_menu = D('menu')->getmenu($menuid);
            foreach ($left_menu as $key=>$val) {
                $left_menu[$key]['sub'] = D('menu')->getmenu($val['id']);
            }
        } else {
            $left_menu[0] = array('id'=>0,'name'=>L('common_menu'));
            $left_menu[0]['sub'] = array();
            if ($r = D('menu')->where(array('often'=>1))->select()) {
                $left_menu[0]['sub'] = $r;

            }
            array_unshift($left_menu[0]['sub'], array('id'=>0,'name'=>L('common_menu_set'),'module_name'=>'index','action_name'=>'often_menu'));
        }
        $this->assign('left_menu', $left_menu);
        $this->display();
    }

    public function panel()
    {
        $message = array();
        if (APP_DEBUG == true) {
            $message[] = array(
                'type' => 'error',
                'content' => "您网站的 DEBUG 没有关闭。",
            );
        }
        if (!function_exists("curl_getinfo")) {
            $message[] = array(
                'type' => 'error',
                'content' => "系统不支持 CURL 。",
            );
        }
        $system_info = array(
            'server_domain' => $_SERVER['SERVER_NAME'] . ' [ ' . gethostbyname($_SERVER['SERVER_NAME']) . ' ]',
            'server_os' => PHP_OS,
            'web_server' => $_SERVER["SERVER_SOFTWARE"],
            'php_version' => PHP_VERSION,
            'mysql_version' => mysql_get_server_info(),
            'upload_max_filesize' => ini_get('upload_max_filesize'),
            'max_execution_time' => ini_get('max_execution_time') . '秒',
            'safe_mode' => (boolean) ini_get('safe_mode') ?  L('yes') : L('no'),
            'zlib' => function_exists('gzclose') ?  L('yes') : L('no'),
            'curl' => function_exists("curl_getinfo") ? L('yes') : L('no'),
            'timezone' => function_exists("date_default_timezone_get") ? date_default_timezone_get() : L('no')
        );
        $this->assign('system_info', $system_info);
        $this->assign('message', $message);
        $this->display();
    }

    public function map()
    {
        $this->display();
    }
}